package com.hehao.java_basic.design_mode.behaviour.strategy.practice;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Damon
 * @date 2023/6/28
 */
public class ReceiptHandleStrategyFactory {
    private static final Map<String, IReceiptHandleStrategy> RECEIPT_HANDLE_STRATEGY_MAP;

    static {
        RECEIPT_HANDLE_STRATEGY_MAP = new HashMap<>();
        RECEIPT_HANDLE_STRATEGY_MAP.put("MT2101", new Mt2101ReceiptHandleStrategy());
        RECEIPT_HANDLE_STRATEGY_MAP.put("MT8104", new Mt8104ReceiptHandleStrategy());
        RECEIPT_HANDLE_STRATEGY_MAP.put("MT1101", new Mt1101ReceiptHandleStrategy());
        RECEIPT_HANDLE_STRATEGY_MAP.put("MT9999", new Mt9999ReceiptHandleStrategy());
    }

    /**
     * 无参构造
     */
    private ReceiptHandleStrategyFactory() {
    }


    /**
     * if判断
     *
     * @param receiptType
     * @return
     */
    public static IReceiptHandleStrategy getReceiptHandleStrategyByIf(String receiptType) {
        IReceiptHandleStrategy receiptHandleStrategy = null;
        if (StringUtils.equals("MT2101", receiptType)) {
            receiptHandleStrategy = new Mt2101ReceiptHandleStrategy();
        } else if (StringUtils.equals("MT8104", receiptType)) {
            receiptHandleStrategy = new Mt8104ReceiptHandleStrategy();
        } else if (StringUtils.equals("MT1101", receiptType)) {
            receiptHandleStrategy = new Mt1101ReceiptHandleStrategy();
        } else if (StringUtils.equals("MT9999", receiptType)) {
            receiptHandleStrategy = new Mt9999ReceiptHandleStrategy();
        }
        return receiptHandleStrategy;
    }

    /**
     * Map存储
     *
     * @param receiptType
     * @return
     */
    public static IReceiptHandleStrategy getReceiptHandleStrategyByMap(String receiptType) {
        return RECEIPT_HANDLE_STRATEGY_MAP.get(receiptType);
    }
}
